package com.etc.dao.impl;

import com.etc.pojo.User;
import com.etc.dao.UserDao;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class UserDaoImpl implements UserDao {
    private SqlSessionFactory sqlSessionFactory;
    public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    public User byiduser(Integer id) {
        SqlSession session = sqlSessionFactory.openSession();
        User user = session.selectOne("byiduser", id);
        session.close();
        return user;
    }

    public Integer delete(Integer id) {
        SqlSession session = sqlSessionFactory.openSession();
        int delete = session.delete("delete", id);
        session.close();
        return delete;
    }

    public List<User> alluser() {
        SqlSession session = sqlSessionFactory.openSession();
        List<User> alluser = session.selectList("alluser");
        session.close();
        return alluser;
    }

    public Integer insert(User user) {
        SqlSession session = sqlSessionFactory.openSession();
        int insert = session.insert("add", user);
        session.close();
        return insert;
    }

    public Integer update(User user) {
        SqlSession session = sqlSessionFactory.openSession();
        int update = session.update("update", user);
        session.close();
        return update;
    }

}
